package huizhi.net;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerTest1 {
    public static void main(String[] args) throws  Exception{
        // 启动服务端，监听8888端口
        ServerSocket server = new ServerSocket(8888);
        // 服务端待命，等待客户端连接。在套接字连接之前，都处于阻塞状态
        Socket accept = server.accept();

        InputStream inputStream = accept.getInputStream();
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\CodeAll\\code\\ExerciseMaven\\src\\main\\java\\huizhi\\net\\8.jpg");
        // buffer
        byte[] buf = new byte[1024];
        // 读取到buf中的字节数
        int readLength;
        while (-1 != (readLength = inputStream.read(buf))) {
            fileOutputStream.write(buf, 0, readLength);
        }
        inputStream.close();
        accept.close();
    }
}
